/**
 * 
 */
package smallChanges.statements;

import java.util.LinkedList;
import java.util.List;

import smallChanges.Tokenization.TokenSet;

/**
 * @author jspacco
 *
 */
public class TryStatement extends CompoundStatement
{
    private List<CatchStatement> catchBlockList=new LinkedList<CatchStatement>();
    private StatementList finallyBlock=StatementList.EMPTY_STATEMENT_LIST;
    //private LabeledStatementBlock finallyBlock=LabeledStatementBlock.EMPTY_LABELED_STATEMENT_BLOCK;
    
    public TryStatement(TokenSet tokenSet) {
        super(tokenSet);
        setStmtType(TRY_STATEMENT);
    }
    
    List<Statement> flattenHelper(List<Statement> list) {
        // the call to the super-method handles the header statement
        // and the body of the try block
        list=super.flattenHelper(list);
        for (CatchStatement c : catchBlockList) {
            list=c.flattenHelper(list);
        }
        list=getFinallyBlock().flattenHelper(list);
        return list;
    }
    
    public void addCatchStatement(CatchStatement s) {
        catchBlockList.add(s);
        s.setParent(this);
    }
    /**
     * @return the finallyBlock
     */
    public StatementList getFinallyBlock()
    {
        return finallyBlock;
    }
    /**
     * @param finallyBlock the finallyBlock to set
     */
    public void setFinallyBlock(StatementList finallyBlock)
    {
        if (finallyBlock!=null) {
            this.finallyBlock = finallyBlock;
            this.finallyBlock.setParent(this);
        }
    }
    /**
     * @return the catchBlockList
     */
    public List<CatchStatement> getCatchBlockList()
    {
        return catchBlockList;
    }
}
